package com.yuneec.droneservice.command;

import com.yuneec.droneservice.request.IResponse;
import com.yuneec.droneservice.utils.ByteUtils;

/**
 * Created by gjw on 2017/3/27.
 */

public class ModifyChannelValues extends BaseCommand {

    /**
     * @param index
     * @param action //0为恢复默认值，1为覆盖默认值，2为叠加至默认值
     * @param value
     */
    public ModifyChannelValues(int index, int action, int value) {
        super(MAV_RC_COMMAND.MAV_RC_CMD_SET_CH_SETTING);
        if (action < 0 || action > 2) {
            throw new IllegalArgumentException("错误的操作类型");
        }
        data = new byte[4];
        data[0] = (byte) index;
        data[1] = (byte) action;
        ByteUtils.uShortToByteArray(data, 2, value, IS_BIGENDIAN);
    }

    public void setValue(int value){
        ByteUtils.uShortToByteArray(data, 2, value, IS_BIGENDIAN);
    }


    @Override
    public IResponse toResponse(byte[] data, int off, int len) {
        int code = data[off + 1] & 0xff;
        return new IResponse(ids(), code);
    }

}
